package com.mutual.help.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mutual.help.dao.UserMapper;
import com.mutual.help.entity.Users;
import com.mutual.help.service.UserService;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, Users> implements UserService {

    @Override
    public void checkLogin(String username, String password) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username,password);
        subject.login(token);
    }

    @Override
    public Users selectUserByUserName(String username) {
        return baseMapper.selectUserByUserName(username);
    }

    @Override
    public List<Users> getAllUser(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Users> usersList = baseMapper.selectList(null);
        return usersList;
    }

    @Override
    public Integer countData() {
        List<Users> usersList = baseMapper.selectList(null);
        return usersList.size();
    }

    @Override
    public Users getByUid(String uid) {
        return baseMapper.getUserById(uid);
    }

    @Override
    public Integer updatePassword(String uid, String pwd) {
        return baseMapper.updatePassword(uid,pwd);
    }
}
